/**
 * 
 */
package com.learn.security.web.aspect;

import java.util.Date;

import org.aspectj.lang.ProceedingJoinPoint;
import org.aspectj.lang.annotation.Around;
import org.aspectj.lang.annotation.Aspect;
import org.springframework.stereotype.Component;


/**
 * AOP
 *      优点：可以获取拦截的类和方法等信息         （与filter对比）
 *      	  可以获取别拦截方法的参数             （与Interceptor对比）
 *      缺点：不能获取HTTP相关信息（如request。。）（与filter和Interceptor对比）
 */
@Aspect
@Component
public class TimeAspect {
	
	@Around("execution(* com.learn.security.web.controller.UserController.*(..))")
	public Object handleControllerMethod(ProceedingJoinPoint pjp) throws Throwable {
		
//		System.out.println("time aspect start");
		
		Object[] args = pjp.getArgs();
		for (Object arg : args) {
			System.out.println("arg is "+arg);
		}
		
		long start = new Date().getTime();
		
		Object object = pjp.proceed();
		
//		System.out.println("time aspect 耗时:"+ (new Date().getTime() - start));
//
//		System.out.println("time aspect end");
		
		return object;
	}

}
